﻿//###HEADER###
//Title: RevitPlus
//Description of Program: Utilzing Revit geometry and properties, user is able to perform an EnergyPlus calculation within Revit.
//Class:IDFCompiler
//Description of Class: Class contains a function, which class all functsion from Batchfiler class   
//       
//By: Steve Chick & Alexander Bernstein
//Date: 12/18/2012
//Version: 001

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Revit_Addin1
{
    //Class contains a function, which calls all functions for BatchFiler class 
    public class IDFcompiler
    {
        public BatchFiler batcher = new BatchFiler();

        //Function calls all functions from BatchFiler class (used to write idf)
        public void Compile()
        {

            String TemplatePath = @"C:\ProgramData\Autodesk\Revit\Addins\2013\RevitPlus\RevitPlusIDFTemplate.idf"; //idf file to be re-written
            String NewTemplatePath = @"C:\EnergyPlusV7-2-0\RevitPlusIDF.idf";//Location the updated idf file is saved

            File.Copy(TemplatePath, NewTemplatePath, true); //Copies template to new location

            StreamReader idf = new StreamReader(@"C:\EnergyPlusV7-2-0\RevitPlusIDF.idf"); //Allows idf to be re-written based on the functions below
            String idffile = idf.ReadToEnd(); // Reads idf inorder to utilize functions below
            idf.Close(); // Closes file
            idf.Dispose();//Disposes of file

            //All functions below are called from Class BatchFiler. Each Re-writes new information to the variable idffile
            batcher.IDFInfo(idffile, out idffile);
            batcher.RunPeriod(idffile, out idffile);
            batcher.BuildingInfo(idffile, out idffile);
            batcher.TimeStep(idffile, out idffile);
            batcher.Materials(idffile, out idffile);
            batcher.Construction(idffile, out idffile);
            batcher.Zones(idffile, out idffile);
            batcher.Surface(idffile, out idffile);
            batcher.Schedule(idffile, out idffile);
            batcher.ZoneEquipment(idffile, out idffile);
            batcher.ZoneEquipmentList(idffile, out idffile);
            batcher.PurchasedAir(idffile, out idffile);
            batcher.ZoneControl(idffile, out idffile);
            batcher.DualSetPoint(idffile, out idffile);
            batcher.Report(idffile, out idffile);
            batcher.Compile();

            StreamWriter newidf = new StreamWriter(@"C:\EnergyPlusV7-2-0\RevitPlusIDF.idf");
            newidf.Write(idffile);//Replaces idf based on idffile
            newidf.Close(); // Closes idf file

            File.Copy(@"C:\EnergyPlusV7-2-0\RevitPlusIDF.idf", @"C:\EnergyPlusV7-2-0\RevitPlus\\" + StoredVariables.ProjectName + "\\" + StoredVariables.ProjectName + ".idf", true);
        }
    }
}